package com.example.tests;
import java.util.List;

import org.testng.annotations.Test;

import com.example.utils.SortedListOf;

public class AllPrintPhonesTests extends TestBase{
	
	@Test
	public void testComparePhonesWithMain(){
		//save old state 
		SortedListOf<ContactData> contactsOnMainPage = app.getModel().getContacts();
		List<PhoneData> contactsOnPhonesPage = app.getAllPrintPhonesHelper().getPhones();
		app.navigateTo().mainPageByGet();
		
		//check sizes of contacts on different pages ('all print phones' and 'main')
        if (contactsOnPhonesPage.size() != contactsOnMainPage.size())
                throw new Error("Contacts count on 'All print phones' page does not coincide with cotacts count on 'Main page'");
        
        //check data of contacts on different pages ('all print phones' and 'main')
        for (int i=0; i < contactsOnPhonesPage.size(); i++){
                String contactDataOnPhonePage = contactsOnPhonesPage.get(i).getContactData();
                String contactFirstNameOnMainPage = contactsOnMainPage.get(i).getFirstName();
                String contactLastNameOnMainPage = contactsOnMainPage.get(i).getLastName();
                String contactPhoneOnMainPage = contactsOnMainPage.get(i).getPhoneOnMainPage();
                
                if ((!contactDataOnPhonePage.contains(contactFirstNameOnMainPage)) ||
                    (!contactDataOnPhonePage.contains(contactLastNameOnMainPage)) ||
                    (!contactDataOnPhonePage.contains(": "+contactPhoneOnMainPage+"\n")))
                        throw new Error(i+" contact on phones page isn't equal to "+i+" contact from main page");
        }
	}
}